﻿namespace WMS6.Web.Inbound
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.InboundDetailServiceRef;
    using WMS6.Web.LoginServiceRef;
    using WMS6.Web.UserControls;
    using WMS6.Web.CommonMethodServiceRef;

    public class ASNDetail : BasePage
    {
        protected HtmlAnchor aExpectedQty;
        protected HtmlAnchor ASkuID;
        protected Button btnCancel;
        protected Button btnSave;
        protected Button btnSaveContinue;
        protected CheckBox chb0;
        protected CheckBox CheckBox1;
        protected DropDownList ddlStatus;
        protected DropDownList ddlUomID;
        protected HtmlForm F4013;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnCaseLevel;
        protected HtmlInputHidden hdnCube;
        protected HtmlInputHidden hdnDataFormat;
        protected HiddenField hdnExpiryDate;
        protected HiddenField hdnExternal;
        protected HtmlInputHidden hdnExternID;
        protected HtmlInputHidden hdnFormart;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnGrossWgt;
        protected HtmlInputHidden hdnIspalletized;
        protected HiddenField hdnLot1;
        protected HiddenField hdnLot10;
        protected HiddenField hdnLot2;
        protected HiddenField hdnLot3;
        protected HiddenField hdnLot4;
        protected HiddenField hdnLot5;
        protected HiddenField hdnLot6;
        protected HiddenField hdnLot7;
        protected HiddenField hdnLot8;
        protected HiddenField hdnLot9;
        protected HtmlInputHidden hdnNetWgt;
        protected HtmlInputHidden hdnOwnerID;
        protected HtmlInputHidden hdnPageQty;
        protected HtmlInputHidden hdnPageType;
        protected HiddenField hdnProductDate;
        protected HtmlInputHidden hdnReceiptID;
        protected HtmlInputHidden hdnSkuID;
        protected HtmlInputHidden hdnType;
        protected HtmlInputHidden hdnUnitPrice;
        protected HtmlInputHidden hdnUomValue;
        protected Label lblAllocateRuleDetail;
        protected Label lblAltSkuID;
        protected Label lblCaseID;
        protected Label lblCube;
        protected Label lblExpectedQty;
        protected Label lblExtendedPrice;
        protected Label lblFeiLv;
        protected Label lblGrossWgt;
        protected Label lblLpnID;
        protected Label lblMsg;
        protected Label lblNetWgt;
        protected Label lblOwnerID;
        protected Label lblPackID;
        protected Label lblPoID;
        protected Label lblReceiptDate;
        protected Label lblReceiptLineID;
        protected Label lblRemark;
        protected Label lblSkuDesc;
        protected Label lblSkuID;
        protected Label lblStatus;
        protected Label lblUdf04;
        protected Label lblUdf09;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblUnitPrice;
        protected Label lblUomID;
        protected Label lblVendorID;
        protected Label lblVendorName;
        protected LotAtrributeCtrl LotAtrributeCtrl1;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected ScriptManager ScriptManager1;
        protected TextBox txtAltSkuID;
        protected TextBox txtCaseID;
        protected TextBox txtCube;
        protected TextBox txtExpectedQty;
        protected TextBox txtExtemdedrice;
        protected TextBox txtFei;
        protected TextBox txtGrossWgt;
        protected TextBox txtLpnID;
        protected TextBox txtNetWgt;
        protected TextBox txtOwnerID;
        protected TextBox txtPackID;
        protected TextBox txtPoID;
        protected TextBox txtReceiptDate;
        protected TextBox txtReceiptLineID;
        protected TextBox txtRemark;
        protected TextBox txtSkuDesc;
        protected TextBox txtSkuID;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;
        protected TextBox txtUnitPrice;
        protected TextBox txtVendorID;
        protected TextBox txtVendorName;
        protected UpdatePanel up1;

        private void BindData2UomList(string packID)
        {
            try
            {
                List<UomList> uomList = CommoneMethodServiceClientProxy.GetInstance().GetUomListByPackID(packID);
                if ((uomList != null) && (uomList.Count > 0))
                {
                    base.BindUomList2DDL(this.ddlUomID, uomList);
                    this.ViewState["UOMLIST"] = uomList;
                    this.CalcSkuWgtCube();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_030") + ex.Message;
                this.txtPackID.Focus();
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("ASN.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnReceiptID.Value.Trim())), false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool success = false;
            try
            {
                if (!string.IsNullOrEmpty(this.txtExpectedQty.Text) && (decimal.Parse(this.txtExpectedQty.Text) <= 0M))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4100_022");
                    this.txtExpectedQty.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(this.ddlUomID.SelectedValue))
                {
                    this.lblMsg.Text = "包装" + this.txtPackID.Text + " 未找到对应的计量单位！";
                    return;
                }
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4100_023");
                    return;
                }
                success = this.InsertReceiptDetail();
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_024") + ex.Message;
                return;
            }
            this.hdnPageQty.Value = "0";
            if (success)
            {
                base.Response.Redirect(string.Format("ASN.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnReceiptID.Value.Trim())), false);
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            bool success = false;
            try
            {
                if (!string.IsNullOrEmpty(this.txtExpectedQty.Text) && (decimal.Parse(this.txtExpectedQty.Text) <= 0M))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4100_022");
                    this.txtExpectedQty.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(this.ddlUomID.SelectedValue))
                {
                    this.lblMsg.Text = "包装" + this.txtPackID.Text + " 未找到对应的计量单位！";
                    return;
                }
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4100_023");
                    return;
                }
                success = this.InsertReceiptDetail();
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_024") + ex.Message;
                return;
            }
            if (success)
            {
                this.lblMsg.Text = this.txtReceiptLineID.Text + base.GetGlobalMsgResource("F4100_009");
                this.txtReceiptLineID.Text = (int.Parse(this.txtReceiptLineID.Text) + 10).ToString();
                this.txtCaseID.Text = "";
                this.txtSkuID.Text = "";
                this.txtAltSkuID.Text = "";
                this.txtPackID.Text = "";
                this.ddlStatus.SelectedValue = "New";
                this.ddlUomID.Items.Clear();
                this.txtLpnID.Text = "";
                this.txtExpectedQty.Text = "";
                this.txtCube.Text = "";
                this.txtGrossWgt.Text = "";
                this.txtNetWgt.Text = "";
                this.txtPoID.Text = "";
                this.txtSkuDesc.Text = "";
                this.txtRemark.Text = "";
                this.hdnPageType.Value = "0";
                this.hdnPageQty.Value = "0";
                this.CountrolsClick();
                this.LotAtrributeCtrl1.ClearControl();
                this.txtSkuID.Focus();
            }
        }

        private void CalcSkuWgtCube()
        {
            List<UomList> uomList = this.ViewState["UOMLIST"] as List<UomList>;
            float uomQty = base.GetUomQtyByUomList(this.ddlUomID.SelectedValue, uomList);
            this.hdnUomValue.Value = uomQty.ToString();
            if (uomQty > 0f)
            {
                float cube = string.IsNullOrEmpty(this.hdnCube.Value.Trim()) ? 0f : float.Parse(this.hdnCube.Value.Trim());
                float grossWgt = string.IsNullOrEmpty(this.hdnGrossWgt.Value.Trim()) ? 0f : float.Parse(this.hdnGrossWgt.Value.Trim());
                float netWgt = string.IsNullOrEmpty(this.hdnNetWgt.Value.Trim()) ? 0f : float.Parse(this.hdnNetWgt.Value.Trim());
                float expectedQty = string.IsNullOrEmpty(this.txtExpectedQty.Text.Trim()) ? 0f : float.Parse(this.txtExpectedQty.Text.Trim());
                this.txtCube.Text = base.GetPreferenceDigit((float) ((cube * uomQty) * expectedQty));
                this.txtGrossWgt.Text = base.GetPreferenceDigit((float) ((grossWgt * uomQty) * expectedQty));
                this.txtNetWgt.Text = base.GetPreferenceDigit((float) ((netWgt * uomQty) * expectedQty));
            }
            else
            {
                this.txtCube.Text = base.GetPreferenceDigit(0);
                this.txtGrossWgt.Text = base.GetPreferenceDigit(0);
                this.txtNetWgt.Text = base.GetPreferenceDigit(0);
            }
        }

        private void CountrolsClick()
        {
            this.txtReceiptLineID.Attributes.Add("RecordValue", "0");
            this.txtReceiptLineID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtReceiptLineID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtOwnerID.Attributes.Add("RecordValue", "0");
            this.txtOwnerID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtOwnerID.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlStatus.Attributes.Add("RecordValue", "0");
            this.ddlStatus.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlStatus.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtCaseID.Attributes.Add("RecordValue", "0");
            this.txtCaseID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtCaseID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtSkuID.Attributes.Add("RecordValue", "0");
            this.txtSkuID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtSkuID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtAltSkuID.Attributes.Add("RecordValue", "0");
            this.txtAltSkuID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtAltSkuID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPackID.Attributes.Add("RecordValue", "0");
            this.txtPackID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPackID.Text + "',this, 'hdnPageQty'); return true; ");
            this.ddlUomID.Attributes.Add("RecordValue", "0");
            if (this.ddlUomID.SelectedItem == null)
            {
                this.ddlUomID.Attributes.Add("onfocusout", "RecordPageValue('',this, 'hdnPageQty'); return true; ");
            }
            else
            {
                this.ddlUomID.Attributes.Add("onfocusout", "RecordPageValue('" + this.ddlUomID.SelectedItem.Text + "',this, 'hdnPageQty'); return true; ");
            }
            this.txtVendorID.Attributes.Add("RecordValue", "0");
            this.txtVendorID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendorID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendorName.Attributes.Add("RecordValue", "0");
            this.txtVendorName.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendorName.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtExpectedQty.Attributes.Add("RecordValue", "0");
            this.txtExpectedQty.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtExpectedQty.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtCube.Attributes.Add("RecordValue", "0");
            this.txtCube.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtCube.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtGrossWgt.Attributes.Add("RecordValue", "0");
            this.txtGrossWgt.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtGrossWgt.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtNetWgt.Attributes.Add("RecordValue", "0");
            this.txtNetWgt.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtNetWgt.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtPoID.Attributes.Add("RecordValue", "0");
            this.txtPoID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtPoID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtLpnID.Attributes.Add("RecordValue", "0");
            this.txtLpnID.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtLpnID.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtRemark.Attributes.Add("RecordValue", "0");
            this.txtRemark.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtRemark.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtReceiptDate.Attributes.Add("RecordValue", "0");
            this.txtReceiptDate.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtReceiptDate.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendorName.Attributes.Add("RecordValue", "0");
            this.txtVendorName.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendorName.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendorName.Attributes.Add("RecordValue", "0");
            this.txtVendorName.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendorName.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtVendorName.Attributes.Add("RecordValue", "0");
            this.txtVendorName.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtVendorName.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf1.Attributes.Add("RecordValue", "0");
            this.txtUdf1.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf1.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf2.Attributes.Add("RecordValue", "0");
            this.txtUdf2.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf2.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf3.Attributes.Add("RecordValue", "0");
            this.txtUdf3.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf3.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf4.Attributes.Add("RecordValue", "0");
            this.txtUdf4.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf4.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf5.Attributes.Add("RecordValue", "0");
            this.txtUdf5.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf5.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf6.Attributes.Add("RecordValue", "0");
            this.txtUdf6.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf6.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf7.Attributes.Add("RecordValue", "0");
            this.txtUdf7.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf7.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf8.Attributes.Add("RecordValue", "0");
            this.txtUdf8.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf8.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf9.Attributes.Add("RecordValue", "0");
            this.txtUdf9.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf9.Text + "',this, 'hdnPageQty'); return true; ");
            this.txtUdf10.Attributes.Add("RecordValue", "0");
            this.txtUdf10.Attributes.Add("onfocusout", "RecordPageValue('" + this.txtUdf10.Text + "',this, 'hdnPageQty'); return true; ");
        }

        protected void ddlUomID_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.CalcSkuWgtCube();
        }

        protected void hndExpectedQty_Click(object sender, EventArgs e)
        {
            this.txtExpectedQty_TextChanged(sender, e);
        }

        private bool InsertReceiptDetail()
        {
            float tempDec = 0f;
            if (string.IsNullOrEmpty(this.txtExpectedQty.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_025");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtSkuID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_026");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtPackID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_027");
                return false;
            }
            if ((this.hdnCaseLevel.Value == "0") && string.IsNullOrEmpty(this.txtCaseID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_028");
                return false;
            }
            DateTime dt = DateTime.Now;
            bool success = false;
            ReceiptDetailInfo receiptDetail = null;
            if (base.DataEntityViewState != null)
            {
                receiptDetail = base.DataEntityViewState as ReceiptDetailInfo;
            }
            else
            {
                receiptDetail = new ReceiptDetailInfo();
            }
            receiptDetail.IsPalletized = this.hdnIspalletized.Value;
            receiptDetail.ReceiptLineID = int.Parse(this.txtReceiptLineID.Text.Trim());
            receiptDetail.ReceiptID = this.hdnReceiptID.Value.Trim();
            receiptDetail.OwnerID = this.txtOwnerID.Text.Trim();
            receiptDetail.Status = this.ddlStatus.SelectedValue;
            receiptDetail.CaseID = this.txtCaseID.Text.Trim();
            receiptDetail.SkuID = this.txtSkuID.Text.Trim();
            receiptDetail.AltSkuID = this.txtAltSkuID.Text.Trim();
            receiptDetail.PackID = this.txtPackID.Text.Trim();
            receiptDetail.UomID = this.ddlUomID.SelectedValue.ToString();
            receiptDetail.VendorID = this.txtVendorID.Text.Trim();
            receiptDetail.VendorName = this.txtVendorName.Text.Trim();
            receiptDetail.LpnID = this.txtLpnID.Text.Trim();
            if (float.TryParse(this.txtUnitPrice.Text.Trim(), out tempDec))
            {
                receiptDetail.UnitPrice = float.Parse(this.txtUnitPrice.Text.Trim());
            }
            else
            {
                receiptDetail.UnitPrice = tempDec;
            }
            if (float.TryParse(this.txtExtemdedrice.Text, out tempDec))
            {
                receiptDetail.ExtendedPrice = float.Parse(this.txtExtemdedrice.Text.Trim());
            }
            else
            {
                receiptDetail.ExtendedPrice = tempDec;
            }
            receiptDetail.Udf1 = this.txtUdf1.Text;
            receiptDetail.Udf2 = this.txtUdf2.Text;
            receiptDetail.Udf3 = this.txtUdf3.Text;
            receiptDetail.Udf4 = this.txtUdf4.Text;
            receiptDetail.Udf5 = this.txtUdf5.Text;
            receiptDetail.Udf6 = this.txtUdf6.Text;
            receiptDetail.Udf7 = this.txtUdf7.Text;
            receiptDetail.Udf8 = this.txtUdf8.Text;
            receiptDetail.Udf9 = this.txtUdf9.Text;
            receiptDetail.Udf10 = this.txtUdf10.Text;
            receiptDetail.ExpectedQty = decimal.Parse(this.txtExpectedQty.Text.Trim());
            if (receiptDetail.ExpectedQty <= 0M)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_029");
            }
            receiptDetail.Cube = float.Parse(this.txtCube.Text.Trim());
            receiptDetail.GrossWgt = float.Parse(this.txtGrossWgt.Text.Trim());
            receiptDetail.NetWgt = float.Parse(this.txtNetWgt.Text.Trim());
            receiptDetail.PoID = this.txtPoID.Text.Trim();
            ReceiptLotInfo lotAttribute = new ReceiptLotInfo();
            receiptDetail.ExternReceiptID = this.hdnExternID.Value;
            receiptDetail.ExternLineID = "";
            receiptDetail.TariffID = "";
            receiptDetail.AdjustedQty = 0.0M;
            receiptDetail.ReceivedQty = 0.0M;
            receiptDetail.RejectedQty = 0.0M;
            receiptDetail.ToLoc = "";
            receiptDetail.ConditionCode = "";
            receiptDetail.CaseCnt = 0.0M;
            receiptDetail.InnerPack = 0.0M;
            receiptDetail.Pallet = 0.0M;
            receiptDetail.OtherUnit1 = 0f;
            receiptDetail.OtherUnit2 = 0f;
            receiptDetail.QcRequired = "";
            lotAttribute.VendorID = this.txtVendorID.Text.Trim();
            lotAttribute.LotAttr01 = "";
            lotAttribute.LotAttr02 = "";
            lotAttribute.LotAttr03 = "";
            lotAttribute.LotAttr04 = "";
            lotAttribute.LotAttr05 = "";
            lotAttribute.LotAttr06 = "";
            lotAttribute.LotAttr07 = "";
            lotAttribute.LotAttr08 = "";
            lotAttribute.LotAttr09 = "";
            lotAttribute.LotAttr10 = this.hdnReceiptID.Value;
            List<Control> lotControls = this.Session["LotAttributeControls"] as List<Control>;
            this.Session["LotAttributeControls"] = null;
            if (lotControls != null)
            {
                foreach (Control ctrl in lotControls)
                {
                    DateTime CS00003;
                    object tempObj = base.Request.Form[this.LotAtrributeCtrl1.ClientID.ToString() + "$" + ctrl.ID.ToString()];
                    string temp = "";
                    if (tempObj != null)
                    {
                        temp = tempObj.ToString();
                    }
                    if (ctrl.ID == "txtProduct")
                    {
                        if (!string.IsNullOrEmpty(temp))
                        {
                            lotAttribute.ProduceDate = DateTime.Parse(temp);
                        }
                        else
                        {
                            CS00003 = new DateTime();
                            lotAttribute.ProduceDate = CS00003;
                        }
                    }
                    else if (ctrl.ID == "txtExpiryDate")
                    {
                        if (!string.IsNullOrEmpty(temp))
                        {
                            lotAttribute.ExpiryDate = DateTime.Parse(temp);
                        }
                        else
                        {
                            CS00003 = new DateTime();
                            lotAttribute.ExpiryDate = CS00003;
                        }
                    }
                    else if (ctrl.ID == "txtExternalLot")
                    {
                        if (!string.IsNullOrEmpty(temp))
                        {
                            lotAttribute.ExternalLot = temp;
                        }
                        else
                        {
                            lotAttribute.ExternalLot = "";
                        }
                    }
                    else
                    {
                        switch (ctrl.ID.Substring(4))
                        {
                            case "1":
                                lotAttribute.LotAttr01 = temp;
                                break;

                            case "2":
                                lotAttribute.LotAttr02 = temp;
                                break;

                            case "3":
                                lotAttribute.LotAttr03 = temp;
                                break;

                            case "4":
                                lotAttribute.LotAttr04 = temp;
                                break;

                            case "5":
                                lotAttribute.LotAttr05 = temp;
                                break;

                            case "6":
                                lotAttribute.LotAttr06 = temp;
                                break;

                            case "7":
                                lotAttribute.LotAttr07 = temp;
                                break;

                            case "8":
                                lotAttribute.LotAttr08 = temp;
                                break;

                            case "9":
                                lotAttribute.LotAttr09 = temp;
                                break;

                            case "10":
                                lotAttribute.LotAttr10 = temp;
                                break;
                        }
                    }
                }
            }
            receiptDetail.EffectiveDate = DateTime.Now;
            receiptDetail.Remark = this.txtRemark.Text.Trim();
            receiptDetail.ReceiptLot = lotAttribute;
            if (!string.IsNullOrEmpty(this.hdnType.Value))
            {
                receiptDetail.UpdatedBy = receiptDetail.CreatedBy;
                if (!string.IsNullOrEmpty(InboundDetailServiceClientProxy.GetInstance().UpdateReceiptDetailInfo(receiptDetail)))
                {
                    success = true;
                }
                return success;
            }
            receiptDetail.CreatedBy = base.UserInfo.UserID;
            receiptDetail.UpdatedBy = receiptDetail.CreatedBy;
            if (!string.IsNullOrEmpty(InboundDetailServiceClientProxy.GetInstance().InsertReceiptDetailInfo(receiptDetail)))
            {
                success = true;
            }
            return success;
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlStatus, "ReceiptStatus");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                string ReceiptID = base.Request.QueryString["ID"];
                this.hdnReceiptID.Value = ReceiptID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["SeqNO"]))
            {
                string LineID = base.Request.QueryString["SeqNO"];
                this.txtReceiptLineID.Text = LineID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["Owner"]))
            {
                string ownerID = base.Request.QueryString["Owner"];
                this.txtOwnerID.Text = ownerID;
                this.hdnOwnerID.Value = ownerID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["Vendor"]))
            {
                string vendor = base.Request.QueryString["Vendor"];
                if (string.Compare(base.Request.QueryString["ReceiptType"], "Return", true) == 0)
                {
                    this.txtVendorID.Text = "";
                    this.txtVendorName.Text = "";
                }
                else
                {
                    this.txtVendorID.Text = vendor;
                }
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["VName"]))
            {
                string vendorName = base.Request.QueryString["VName"];
                if (string.Compare(base.Request.QueryString["ReceiptType"], "Return", true) == 0)
                {
                    this.txtVendorName.Text = "";
                }
                else
                {
                    this.txtVendorName.Text = vendorName;
                }
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ExternID"]))
            {
                this.hdnExternID.Value = base.Request.QueryString["ExternID"];
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["Ispalletized"]))
            {
                this.hdnIspalletized.Value = base.Request.QueryString["Ispalletized"];
            }
            else
            {
                this.hdnIspalletized.Value = "N";
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ReceiptType"]))
            {
                string ReceiptType = base.Request.QueryString["ReceiptType"];
                if (ReceiptType != "CaseLevel")
                {
                    this.lblCaseID.Visible = false;
                    this.txtCaseID.Visible = false;
                    this.hdnCaseLevel.Value = "1";
                }
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["type"]))
            {
                this.btnSaveContinue.Enabled = false;
                this.hdnType.Value = base.Request.QueryString["type"];
                this.SetTextBoxByReceiptDetailInfo();
            }
            else
            {
                this.ddlStatus.SelectedValue = "New";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
                WMS6.Web.LoginServiceRef.PreferenceInfo preferenceInfo = base.UserInfo.Preference;
                this.hdnFormart.Value = preferenceInfo.Digits_No;
                this.CountrolsClick();
            }
            this.LotAtrributeCtrl1.LoadData(this.txtSkuID.Text, this.hdnOwnerID.Value, this.LotAtrributeCtrl1.ClientID.ToString(), false, 4);
        }

        private void SetTextBoxByReceiptDetailInfo()
        {
            try
            {
                ReceiptDetailInfo receiptDetail = InboundDetailServiceClientProxy.GetInstance().GetReceiptDetailInfoByID(this.hdnReceiptID.Value, this.txtReceiptLineID.Text);
                if (receiptDetail != null)
                {
                    this.txtReceiptLineID.Text = receiptDetail.ReceiptLineID.ToString();
                    this.txtOwnerID.Text = receiptDetail.OwnerID;
                    this.ddlStatus.SelectedValue = receiptDetail.Status;
                    this.txtCaseID.Text = receiptDetail.CaseID;
                    this.txtSkuID.Text = receiptDetail.SkuID;
                    this.hdnSkuID.Value = receiptDetail.SkuID;
                    this.txtSkuID_TextChanged(null, null);
                    this.txtUnitPrice.Text = base.GetPreferenceDigit(receiptDetail.UnitPrice.ToString());
                    this.hdnUnitPrice.Value = base.GetPreferenceDigit(receiptDetail.UnitPrice.ToString());
                    this.txtExtemdedrice.Text = base.GetPreferenceDigit(receiptDetail.ExtendedPrice.ToString());
                    this.txtAltSkuID.Text = receiptDetail.AltSkuID;
                    this.txtPackID.Text = receiptDetail.PackID;
                    this.txtPackID_TextChanged(null, null);
                    this.ddlUomID.SelectedValue = receiptDetail.UomID;
                    List<UomList> uomList = this.ViewState["UOMLIST"] as List<UomList>;
                    float uomQty = base.GetUomQtyByUomList(this.ddlUomID.SelectedValue, uomList);
                    this.hdnUomValue.Value = uomQty.ToString();
                    this.txtVendorID.Text = receiptDetail.VendorID;
                    this.txtVendorName.Text = receiptDetail.VendorName;
                    this.txtExpectedQty.Text = base.GetPreferenceDigit(receiptDetail.ExpectedQty);
                    this.txtCube.Text = base.GetPreferenceDigit(receiptDetail.Cube);
                    this.txtGrossWgt.Text = base.GetPreferenceDigit(receiptDetail.GrossWgt);
                    this.txtNetWgt.Text = base.GetPreferenceDigit(receiptDetail.NetWgt);
                    float CS00002 = receiptDetail.Cube / (Convert.ToSingle(receiptDetail.ExpectedQty) * uomQty);
                    this.hdnCube.Value = CS00002.ToString();
                    CS00002 = receiptDetail.GrossWgt / (Convert.ToSingle(receiptDetail.ExpectedQty) * uomQty);
                    this.hdnGrossWgt.Value = CS00002.ToString();
                    this.hdnNetWgt.Value = (receiptDetail.NetWgt / (Convert.ToSingle(receiptDetail.ExpectedQty) * uomQty)).ToString();
                    this.txtPoID.Text = receiptDetail.PoID;
                    this.txtLpnID.Text = receiptDetail.LpnID;
                    this.hdnExternID.Value = receiptDetail.ExternReceiptID;
                    this.txtRemark.Text = receiptDetail.Remark;
                    this.txtReceiptDate.Text = base.GetPreferenceShortDate(receiptDetail.ReceivedDate);
                    this.hdnLot1.Value = receiptDetail.ReceiptLot.LotAttr01;
                    this.hdnLot2.Value = receiptDetail.ReceiptLot.LotAttr02;
                    this.hdnLot3.Value = receiptDetail.ReceiptLot.LotAttr03;
                    this.hdnLot4.Value = receiptDetail.ReceiptLot.LotAttr04;
                    this.hdnLot5.Value = receiptDetail.ReceiptLot.LotAttr05;
                    this.hdnLot6.Value = receiptDetail.ReceiptLot.LotAttr06;
                    this.hdnLot7.Value = receiptDetail.ReceiptLot.LotAttr07;
                    this.hdnLot8.Value = receiptDetail.ReceiptLot.LotAttr08;
                    this.hdnLot9.Value = receiptDetail.ReceiptLot.LotAttr09;
                    this.hdnLot10.Value = receiptDetail.ReceiptLot.LotAttr10;
                    this.txtUdf1.Text = receiptDetail.Udf1;
                    this.txtUdf2.Text = receiptDetail.Udf2;
                    this.txtUdf3.Text = receiptDetail.Udf3;
                    this.txtUdf4.Text = receiptDetail.Udf4;
                    this.txtUdf5.Text = receiptDetail.Udf5;
                    this.txtUdf6.Text = receiptDetail.Udf6;
                    this.txtUdf7.Text = receiptDetail.Udf7;
                    this.txtUdf8.Text = receiptDetail.Udf8;
                    this.txtUdf9.Text = receiptDetail.Udf9;
                    this.txtUdf10.Text = receiptDetail.Udf10;
                    this.hdnProductDate.Value = base.GetPreferenceShortDate(receiptDetail.ReceiptLot.ProduceDate);
                    this.hdnExpiryDate.Value = base.GetPreferenceShortDate(receiptDetail.ReceiptLot.ExpiryDate);
                    this.hdnExternal.Value = receiptDetail.ReceiptLot.ExternalLot;
                    base.DataEntityViewState = receiptDetail;
                }
                else
                {
                    this.lblMsg.Text = this.hdnReceiptID.Value + base.GetGlobalMsgResource("F4100_021");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void txtAltSkuID_TextChanged(object sender, EventArgs e)
        {
            this.txtSkuID_TextChanged(null, null);
            this.txtVendorID_TextChanged(null, null);
            this.hdnPageType.Value = "0";
            this.txtAltSkuID.Focus();
        }

        protected void txtExpectedQty_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtExpectedQty.Text.Trim()))
                {
                    if (float.Parse(this.txtExpectedQty.Text.Trim()) > 0f)
                    {
                        this.CalcSkuWgtCube();
                    }
                    else
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F4100_033");
                        this.lblMsg.Visible = true;
                    }
                }
            }
            catch (Exception)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_034");
                this.lblMsg.Visible = true;
            }
            this.hdnPageType.Value = "0";
            this.txtExpectedQty.Focus();
        }

        protected void txtPackID_TextChanged(object sender, EventArgs e)
        {
            this.BindData2UomList(this.txtPackID.Text.Trim());
            this.hdnPageType.Value = "0";
            this.txtPackID.Focus();
        }

        protected void txtSkuID_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string skuID = this.txtSkuID.Text.Trim();
                if (string.IsNullOrEmpty(skuID))
                {
                    this.txtSkuDesc.Text = "";
                    this.txtPackID.Text = "";
                    this.txtCube.Text = "";
                    this.hdnCube.Value = "";
                    this.txtGrossWgt.Text = "";
                    this.hdnGrossWgt.Value = "";
                    this.txtNetWgt.Text = "";
                    this.hdnNetWgt.Value = "";
                    this.txtUnitPrice.Text = "";
                    this.hdnUnitPrice.Value = "";
                    this.txtExtemdedrice.Text = "";
                    this.ddlUomID.Items.Clear();
                }
                else
                {
                    CommonMethodServiceRef.SkuInfo skuInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.hdnOwnerID.Value, skuID, "", "SKU") as CommonMethodServiceRef.SkuInfo;
                    if ((((skuInfo != null) && !string.IsNullOrEmpty(skuInfo.SkuID)) && !string.IsNullOrEmpty(skuInfo.OwnerID)) && (skuInfo.IsActive == "Y"))
                    {
                        this.txtSkuDesc.Text = skuInfo.Descr;
                        this.txtPackID.Text = skuInfo.PackID;
                        this.txtCube.Text = base.GetPreferenceDigit(skuInfo.Cube);
                        this.hdnCube.Value = this.txtCube.Text;
                        this.txtGrossWgt.Text = base.GetPreferenceDigit(skuInfo.GrossWgt);
                        this.hdnGrossWgt.Value = this.txtGrossWgt.Text;
                        this.txtNetWgt.Text = base.GetPreferenceDigit(skuInfo.NetWgt);
                        this.hdnNetWgt.Value = this.txtNetWgt.Text;
                        this.txtUnitPrice.Text = base.GetPreferenceDigit(skuInfo.CostPrice.ToString());
                        this.hdnUnitPrice.Value = base.GetPreferenceDigit(skuInfo.CostPrice.ToString());
                        if (!string.IsNullOrEmpty(this.txtExpectedQty.Text.Trim()))
                        {
                            this.txtExtemdedrice.Text = base.GetPreferenceDigit((float.Parse(this.txtUnitPrice.Text.Trim()) * float.Parse(this.txtExpectedQty.Text.Trim())).ToString());
                        }
                        this.BindData2UomList(this.txtPackID.Text.Trim());
                        this.txtExpectedQty.Focus();
                    }
                    else
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F4100_031");
                        this.txtSkuID.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.txtSkuID.Focus();
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>CloseSearch();false;</script>", false);
            }
            this.hdnPageType.Value = "0";
        }

        protected void txtUnitPrice_TextChanged(object sender, EventArgs e)
        {
            double doubleTemp = 0.0;
            if (double.TryParse(this.txtExpectedQty.Text.Trim(), out doubleTemp) && double.TryParse(this.txtUnitPrice.Text.Trim(), out doubleTemp))
            {
                this.txtExtemdedrice.Text = (double.Parse(this.txtExpectedQty.Text.Trim()) * double.Parse(this.txtUnitPrice.Text.Trim())).ToString();
            }
            this.hdnUnitPrice.Value = this.txtUnitPrice.Text.Trim();
        }

        protected void txtVendorID_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtVendorID.Text))
                {
                    VendorInfo vendor = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtVendorID.Text, "VENDOR") as VendorInfo;
                    if (vendor != null)
                    {
                        this.txtVendorName.Text = vendor.Company;
                    }
                    else
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F4100_032");
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            this.hdnPageType.Value = "0";
            this.txtVendorID.Focus();
        }
    }
}

